<html>
<head><title>SUDOKU Options</title>
<script type="text/javascript">

// Saves options to localStorage.
function save_options() {
	var ahv = document.getElementById("allowhard").checked;
	console.log("ah checked:", ahv, "type=", typeof(ahv));
	localStorage["options.allowhard"] = document.getElementById("allowhard").checked;
	localStorage["options.hinttips"] = document.getElementById("hinttips").checked;
	localStorage["options.hlcross"] = document.getElementById("hlcross").checked;
	localStorage["options.hlerrors"] = document.getElementById("hlerrors").checked;

	// Update status to let user know options were saved.
	var status = document.getElementById("status");
	status.innerHTML = "Options Saved.";
	setTimeout(function() { status.innerHTML = ""; }, 750);
}

// Restores select box state to saved value from localStorage.
function restore_options() {
	var ah = localStorage["options.allowhard"];
	console.log("loading allowhard:", ah, "type:", typeof(ah));
	document.getElementById("allowhard").checked = ("true"==localStorage["options.allowhard"]);
	document.getElementById("hinttips").checked =  ("true"==localStorage["options.hinttips"]);
	document.getElementById("hlcross").checked =   ("true"==localStorage["options.hlcross"]);
	document.getElementById("hlerrors").checked =  ("true"==localStorage["options.hlerrors"]);
}

function add_bookmark() {
	chrome.bookmarks.create({
		"parentId": "1",
		"title": "SUDOKU",
		"url": chrome.extension.getURL("gridmenu.html")
	});
}

</script>
</head>
<body onload="restore_options()">

<h1>Main Options</h1>
<input type="checkbox" id="allowhard">Allow hard puzzles<br>

<h1>Display Options</h1>
<input type="checkbox" id="hinttips"/>Show tooltips with hints<br>
<input type="checkbox" id="hlcross"/>Highlight the row and column under the cursor<br>
<input type="checkbox" id="hlerrors"/>Highlight wrongly placed numbers<br>

<br>
<button onclick="save_options()">Save</button>
<span id="status"></span>
<hr>
<button onclick="add_bookmark()">Add SUDOKU to your bookmarks</button>
</body>
</html>

